<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>客户列表</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<!-- 页签1：客户管理 -->
		<div tabid="tabA" title="客户管理" lselected="true">
			<div class="searchArea">
				<form id="searchBar">
					<div class="fieldset1 clearFix">
						<div class="FXBR">
							<div class="fieldBox">
								<div class="label">客户名称</div>
								<div class="field">
									<input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">证件号码</div>
								<div class="field">
									<input name="certNo" id="certNo" type="text" class="ui-textbox" value="" ligerui="width: 160">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">客户类型</div>
								<div class="field">
									<select name="cstTypCd" id="cstTypCd" ligerui="width: 160">
										<option value=" " seleted>请选择</option>
										<c:forEach items="${searchSelectCsttypcdlist }" var="csttypcd">
											<option value="${csttypcd.key }">${csttypcd.value }</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">客户属性</div>
								<div class="field">
									<select name="cstRlTyp" id="cstRlTyp" ligerui="width: 160">
										<option value=" ">请选择</option>
										<c:forEach items="${cstRlTypCdList }" var="cstRlcd">
											<c:if test="${currentCstRlType == cstRlcd.key }">
												<option value="${cstRlcd.key }" selected>${cstRlcd.value }</option>
											</c:if>
											<c:if test="${currentCstRlType != cstRlcd.key }">
												<option value="${cstRlcd.key }">${cstRlcd.value }</option>
											</c:if>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">所属机构</div>
								<div class="field">
									<input name="buOrgCd" id="buOrgCd" type="text" value="" placeholder="请选择"  ltype="combobox">
									<%-- <select name="buOrgCd" id="buOrgCd" ligerui="width: 160">
                                        <option value=" " seleted>请选择</option>
                                        <c:forEach items="${orgListList }" var="org">
                                            <c:if test="${currentBuOrgCd == org.key }">
                                                <option value="${org.key }" selected>${org.value }</option>
                                            </c:if>
                                            <c:if test="${currentBuOrgCd != org.key }">
                                                <option value="${org.key }">${org.value }</option>
                                            </c:if>
                                        </c:forEach>
                                    </select> --%>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">风险标记</div>
								<div class="field">
									<select name="rskMarkerCd" id="rskMarkerCd" ligerui="width: 160">
										<option value=" " seleted>请选择</option>
										<option value="1" seleted>是</option>
										<option value="0" seleted>否</option>
									</select>
								</div>
							</div>
						</div>
						<!-- 隐藏当前选中的客户ID信息 -->
						<div class="fieldBox" style="display:none;">
							<div class="field">
								<input name="sCstId" id="sCstId" type="text" class="ui-textbox" value="">
							</div>
						</div>
						<div class="clearFix"></div>
						<div class="btnsBox formBtns notRight">
							<span id="searchBtn" class="sq-button-round">查询</span>
							<span id="clearBtn" class="sq-button-round">清空</span>
							<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
							<span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
							<%-- <a target="_blank" href="<%=path%>/system/sysulfilesrec/downLoad.do?fileName='我是谁'&filePath='attachments/11000/customer/20170406/5df071c5f6da4255b5a9a0f4a4ae3bda.png'">下载附件</a> --%>
						</div>
					</div>
				</form>
			</div>
			<div id="ligergrid1" class="sq-grid"></div>
		</div>
		<!-- 页签2：流程跟踪 -->
		<div tabid="tabB" title="流程跟踪" id="tabBId" style="dis">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>
	</div>
</div>

<!-- 客户类型 -->
<div id="div_customer_type" style="display:none">
	<form id="div_customer_type_form">
		<div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
			<div class="fieldBox col_50">
				<div class="label">客户类型</div>
				<div class="field">
					<select name="win_select_customer_type" id="win_select_customer_type" data-value="" validate="{required:true, select: true}">
						<option value="">请选择</option>
						<c:forEach items="${searchSelectCsttypcdlist }" var="csttypcd" begin="0" step="1" varStatus="status">
							<c:if test="${csttypcd.key == 1}">
								<option value="${csttypcd.key }">${csttypcd.value }</option>
							</c:if>
							<c:if test="${csttypcd.key != 1}">
								<option value="${csttypcd.key }">${csttypcd.value }</option>
							</c:if>
						</c:forEach>
					</select>
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<!-- 可以处理隐藏操作-自然人 -->
			<div id="win_np_block_id" style="display:block">
				<div class="fieldBox col_50">
					<div class="label" id="div_customer_name_column_tip">客户名称</div>
					<div class="field">
						<input name="winNpCstNm" id="winNpCstNm" type="text" class="ui-textbox" value="" validate="{required:true,nmcharacter:true,maxlength:20}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">证件类型</div>
					<div class="field">
						<select name="winCertTypCd" id="winCertTypCd" data-value="" validate="{required:true, select: true}">
							<c:forEach items="${searchSelectCertTypCdList }" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
									<option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
								<c:if test="${status.index != 0}">
									<option value="${kv.key }">${kv.value }</option>
								</c:if>
							</c:forEach>
						</select>
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label" id="div_customer_type_column_tip">证件号</div>
					<div class="field">
						<input name="winNpCertNo" id="winNpCertNo" type="text" class="ui-textbox" value="" validate="{required:true}">
						<span class="requiredSymbol">*</span>
						<%--<span class="addNpVerifyID" id="sNpVerifyID">--%>
		                        	<%--<a href="javascript:;" id="addNpVerifyID" pass='n' class="liger_tip" title="未验证"><i class="sqIco sqIco_8"></i></a>--%>
		                    	<%--</span>--%>
					</div>
				</div>
			</div>

			<!-- 可以处理隐藏操作-法人 -->
			<div id="win_corp_block_id" style="display:none">
				<div class="fieldBox col_50">
					<div class="label" id="div_customer_name_column_tip">客户名称</div>
					<div class="field">
						<input name="corpCstNm" id="corpCstNm" type="text" class="ui-textbox" value="" validate="{required:true,maxlength:30}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">证件类型</div>
					<div class="field">
						<select name="corpCertTypCd" id="corpCertTypCd" data-value="" validate="{required:true, select: true}">
							<c:forEach items="${searchSelectLPCertTypCdList }" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
									<option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
								<c:if test="${status.index != 0}">
									<option value="${kv.key }">${kv.value }</option>
								</c:if>
							</c:forEach>
						</select>
						<span class="requiredSymbol">*</span>
					</div>
				</div>

				<div class="fieldBox col_50">
					<div class="label" id="div_customer_type_column_tip">证件证号</div>
					<div class="field">
						<input name="corpCertNo" id="corpCertNo" type="text" class="ui-textbox" value="" validate="{required:true}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>

				<div class="fieldBox col_50">
					<div class="label" id="div_customer_name_column_tip">法定代表人</div>
					<div class="field">
						<input name="corpLowerNm" id="corpLowerNm" type="text" class="ui-textbox" value="" validate="{required:true,nmcharacter:true,maxlength:20}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">法人证件类型</div>
					<div class="field">
						<select name="corpForCertTypCd" id="corpForCertTypCd" data-value="" validate="{required:true, select: true}">
							<c:forEach items="${searchSelectCertTypCdList }" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
									<option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
								<c:if test="${status.index != 0}">
									<option value="${kv.key }">${kv.value }</option>
								</c:if>
							</c:forEach>
						</select>
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">法人证件号码</div>
					<div class="field">
						<input name="corpLowerCertNo" id="corpLowerCertNo" type="text" class="ui-textbox" value="" validate="{required:true}">
						<span class="requiredSymbol">*</span>
						<span class="addNpVerifyID" id="sCorpVerifyId">
		                        	<a href="javascript:;" id="addCorpVerifyID" pass='n' class="liger_tip" title="未验证"><i class="sqIco sqIco_8"></i></a>
		                    	</span>
					</div>
				</div>
			</div>
		</div>
	</form>
</div>

<script type="text/javascript">
	var grid = null;
	var pageInApp = {
		flag: true
	};
	var pageInTab=null;//页签
	var loadedTabs = [];
	var _mySelfIDImgUrl="";//我自己的身份证图片地址,待验证过后返回
	$(function () {
		initOrgTree();//初始化组织架构树
		initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		initTab();//初始化页签
		searchBtnEvent();
		clearBtnEvent();
		npVerifyIDEvent();
	});

	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"cstTypCd":" ",
				"cstRlTyp":" ",
				"rskMarkerCd":""
			});
			liger.get("buOrgCd").clear();//清空树
		});
	}

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}

	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			data["crtTm"] = $("#crtTm").val();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}

	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		data["isAuth"] = "true";
		return data;
	}

	//初始化组织架构树
	var searchOrgTree = null;
	function initOrgTree(){
		$("#buOrgCd").ligerComboBox({
			selectBoxWidth: 240,
			selectBoxHeight: 150,
			treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
			textField:"tName",
			valueField:"tCode",
			tree: {
				url: '<%=path%>/customer/cstbscinfo/initOrgTree.do',
				ajaxType: 'get',
				checkbox: false,
				parentIcon: "none",
				childIcon: "none",
				textFieldName:"tName",
				idFieldName:"tCode",
				onSuccess: function () {
				}
			}
		});
	}

	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url: '<%=path%>/customer/cstbscinfo/initList.do',
			method : 'get',
			parms:getSearchParams(),
			columns: [
				{ display: '客户名称', name: 'cstNm', minWidth: 180 , align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) {
						if(StringUtils.isEmpty(value)){
							value = "";
						}
						var h = '';
						h='<a href="javascript:showDetail(';
						h+="'"+rowdata.id+"'";
						h+=",'"+rowdata.cstTypCd+"'";
						h+=')">'+value+'</a>'
						return h;
					}},
				{ display: '客户性质', name: 'cstStsCdNm', width: 100, enabledSort:true },
				/* { display: '客户级别', name: 'cstLvlCdNm', width: 120 , enabledSort:true}, */
				{ display: '客户类型', name: 'cstTypCd', width: 1,align:'left', enabledSort:true, hide:true},
				{ display: '客户类型', name: 'cstTypCdNm', width: 120, enabledSort:true},
				{ display: '证件/组织机构代码', name: 'certNo', width: 160, align:'center', enabledSort:true},
				{ display: '创建时间', name: 'crtTm', width: 160 , render:renderDate, enabledSort:true},
				{ display: '风险标记', name: 'rskCdNms', width: 80 , enabledSort:false
				},
				getGridOperColumnContent()
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,
			rownumbers:true,
			//选择行事件
			onSelectRow: function(rowdata, rowid, rowobj){
				//设置当前选择的客户ID值
				$("#sCstId").val(rowdata.id);
			},
			//取消选择行事件
			onUnSelectRow : function(rowdata, rowid, rowobj){
				//清空当前选择的客户ID值
				$("#sCstId").val('');
			}
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		grid.options.isSingleCheck=true;
	}

	//隐藏掉操作列
	function getGridOperColumnContent(){
		var data = {
			display: '操作',
			isSort: false,
			width: 300,
			align:'left',
			render: function (rowdata, rowindex, value){
				var h="";
				h+='<a class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
				h+="'"+rowdata.id+"'";
				h+=",'"+rowdata.cstTypCd+"'";
				h+=",'ligergrid_bankacc'";
				h+=")\"><i class=\"sqBtnIco_4\"></i>"+LogUtils.LOG_CMM_GRID_BTN_MODIFY+"</a>";

				//基础变更
				var _audStsCd = rowdata.audStsCd;
				if( _audStsCd == "11"){//不允许立项、不允许变更(11:基本信息变更中)
// 	                    	var _flowNO = rowdata.flowNo;
// 	                    	if(rowdata.flowDataId != null && rowdata.flowNo != null){
// 	        	                h+='<a class="sq-button-hasicon" title="'+_flowNO+'" href="javascript:commShowFlow(';
// 	        	                h+="'"+rowdata.pinstId2+"'";
// 	        	                h+=",'"+rowdata.audStsCd2+"'";
// 	        	                h+=",'"+rowdata.flowDataId+"'";
// 	        	                h+=")\"><i class='sqBtnIco_32'></i>"+_flowNO.substr(6)+"</a>";
// 	        				}else{
					h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>立项申请</font>';

					h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>基础变更</font>';
// 	        				}
				}else{//可立项、可变更
					h+='<a class="sq-button-hasicon" alt="立项申请" href="javascript:createProjectRow(';
					h+="'"+rowdata.id+"'";
					h+=",'"+rowdata.cstNm+"'";
					h+=",'ligergrid_bankacc'";
					h+=")\"><i class=\"sqBtnIco_27\"></i>"+LogUtils.LOG_CUST_GRID_CREAT_PROJECT+"</a>";

					h+='<a class="sq-button-hasicon" alt="基础变更" href="javascript:modifyApply(';
					h+="'"+rowdata.id+"'";
					h+=",'"+rowdata.cstTypCd+"'";
					h+=",'"+_audStsCd+"'"; //客户状态（13：已立项  14：有担保项目）
					h+=",'ligergrid_bankacc'";
					h+=")\"><i class=\"sqBtnIco_4\"></i>基础变更</a>";
				}
				return h;
			}
		}
		return data;
	}

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	//删除数据
	function deleteRecord(){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length == 0){
			UIUtils.alertWarning(LogUtils.LOG_CMM_SELECT_MORE_ROW);
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.SQconfirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var _url = "<%=path%>/customer/cstbscinfo/removeByIds.do";
			AjaxUtils.ajaxPost(_url, {ids:JSON.stringify(_ids)}, function(msg){
				if(msg.success == 1){
					grid.reload();
				}else{
					UIUtils.alertError(msg.info);
				}
			},true);
		});
	};

	//查看数据
	function showDetail(_id,_cstTypCd){
		//1 自然人  2 法人
		if(_cstTypCd == 1){
			parent.mainApp.f_addTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpDetailPage.do?id='+_id);
		}else if(_cstTypCd == 2){
			parent.mainApp.f_addTab('tab_customer_corp_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpDetailPage.do?id='+_id);
		}
	}

	//新增数据,先选择客户类型,然后做好验证后在进入具体的页面
	var ligerPersonForm;
	function add(){
		$.ligerDialog.SQopen({
			width: 800,
			top: 100,
			buttons: [
				{
					text: "确定", cls: 'l-dialog-btn-ok', onclick:function(){
						saveNpInfo();
					}
				}, {
					text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
						$.ligerDialog.hide();
					}
				}
			],
			title : '新增',
			target: $("#div_customer_type")
		});
		ligerPersonForm = $("#div_customer_type_form").ligerForm({
			validate: true
		});

		//新增客户类型选择事件
		winSelectCustomerTypeChangeEvent();
		//是否验证证件号
		checkIsOrNot();

		//清空字段值
		resetAddCstNpForm(ligerPersonForm);
	}

	//点击自然人保存按钮
	function saveNpInfo(){
		if (!ligerPersonForm.valid()) {
			UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
			return false; //验证不通过，不执行以下代码
		}
		var data = ligerPersonForm.getData();
		//处理接收参数
		//1 自然人  2法人
		if(data.win_select_customer_type == CustomerConstant.CST_TYPE_NP_CD){
			// if($("#winCertTypCd").val()==0){
			// 	//必须是身份证验证通过才行
			// 	if($("#addNpVerifyID").attr("pass") == 'n'){
			// 		UIUtils.alertWarning("请验证身份证信息是否正确!");
			// 		return;
			// 	}
			// }
			data["npCertTypCd"] = data.winCertTypCd;
			data["cstNm"] = data.winNpCstNm;
			data["certNo"] = data.winNpCertNo;
			toCheckNpPage(data);//传递表单数据
		}else if(data.win_select_customer_type == CustomerConstant.CST_TYPE_CORP_CD){
			if($("#corpForCertTypCd").val()==0){
				//必须是身份证验证通过才行
				if($("#addCorpVerifyID").attr("pass") == 'n'){
					UIUtils.alertWarning("请验证身份证信息是否正确!");
					return;
				}
			}
			data["cstNm"] = data.corpCstNm;
			data["certNo"] = data.corpCertNo;
			data["certTypCd"] = data.corpCertTypCd;
			data["corpForCertTypCd"] = data.corpForCertTypCd;
			checkExistCorpInfo(data);
		}else{
			UIUtils.alertWarning("请选择新增类型!");
		}
	}

	//重置新增选择表单
	function resetAddCstNpForm(ligerPersonForm){
		//赋值给验证图标默认值
		$("#sNpVerifyID").html(getVerfiedIDHtmlDefault());
		$("#sCorpVerifyId").html(getCorpVerfiedIDHtmlDefault());
		//清理自然人数据
		$("#winNpCstNm").val("");
		$("#winCertTypCd").val("");
		$("#winNpCertNo").val("");
		//清理法人数据
		$("#corpCertTypCd").val("");
		$("#corpCertNo").val("");
		$("#corpForCertTypCd").val("");
		$("#corpLowerNm").val("");
		$("#corpLowerCertNo").val("");
		$("#corpCstNm").val("");

		//释放自然人
		liger.get("win_select_customer_type").setEnabled();
		liger.get("winNpCstNm").setEnabled();
		liger.get("winCertTypCd").setEnabled();
		liger.get("winNpCertNo").setEnabled();
		//释放法人
		liger.get("corpCstNm").setEnabled();
		liger.get("corpLowerNm").setEnabled();
		liger.get("corpForCertTypCd").setEnabled();
		liger.get("corpLowerCertNo").setEnabled();
	}

	//检查是否存在客户信息
	function checkExistCorpInfo(data){
		var _url = '<%=path%>/customer/cstbscinfo/getExistCorp.do';
		AjaxUtils.ajaxGet(_url, data, function(msg){
			if(msg.success == 1){
				$.ligerDialog.SQconfirm(LogUtils.LOG_CUST_INFO_EXIST, function (flag) {
					if(flag == true){
						var _id = msg.data.cId;
						parent.mainApp.f_addTab('tab_customer_corp_update'+_id,'修改客户','<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpAddPage.do?id='+_id);
						$.ligerDialog.hide();//关闭新增窗口
					}
				});
			}else if(msg.success == 3){//可以跳转
				var param = "?cstNm="+data.cstNm+"&certNo="+data.certNo+"&certTypCd="+data.certTypCd
						+"&corpLowerNm="+data.corpLowerNm
						+"&corpForCertTypCd="+data.corpForCertTypCd
						+"&corpLowerCertNo="+data.corpLowerCertNo;
				var timestamp = (new Date()).valueOf();
				parent.mainApp.f_addTab('addCorpCustomer'+timestamp,'新增客户','<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpAddPage.do'+param);
				$.ligerDialog.hide();//关闭新增窗口
			}else if(msg.success == 2){
				UIUtils.alertError(msg.info);
			}
		},true);
	};

	//跳转到修改自然人界面
	function toCheckNpPage(data){
		var _url = '<%=path%>/customer/cstbscinfo/getExistNp.do';
		AjaxUtils.ajaxGet(_url, data, function(msg){
			if(msg.success == 1){
				$.ligerDialog.SQconfirm(LogUtils.LOG_CUST_INFO_EXIST, function (flag) {
					if(flag == true){
						//跳转到修改页面
						var _id = msg.data.cId;
						parent.mainApp.f_addTab('tab_customer_np_update'+_id,'修改客户','<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpAddPage.do?id='+_id);
						$.ligerDialog.hide();//关闭新增窗口
					}
				});
			}else if(msg.success == 3){
				//跳转到新增页面
				var param = "?cstNm="+data.cstNm+"&certNo="+data.certNo+"&npCertTypCd="+data.npCertTypCd+"&imgUrl="+_mySelfIDImgUrl;
				var timestamp = (new Date()).valueOf();
				parent.mainApp.f_addTab("addNpCustomer"+timestamp,"新增客户","<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpAddPage.do"+param);
				$.ligerDialog.hide();//关闭新增窗口
			}else{
				UIUtils.alertError(msg.info);
			}
		},true);
	}

	//更新
	function modifyRow(_id, _cstTypCd){
		//1 自然人  2 法人
		if(_cstTypCd == 1){
			parent.mainApp.f_addTab('tab_customer_np_update'+_id,'修改客户','<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpAddPage.do?id='+_id);
		}else if(_cstTypCd == 2){
			parent.mainApp.f_addTab('tab_customer_corp_update'+_id,'修改客户','<%=path%>/customer/cstbscinfo/toCustCstBacInfoCorpAddPage.do?id='+_id);
		}
	}

	//基础信息变更申请
	function modifyApply(_id, _cstTypCd, _audStsCd){
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		//1 自然人  2 法人
		if(_cstTypCd == 1){
			Add_navTab('tab_customer_np_mod'+_id,'自然人变更申请','<%=path%>/customer/cstbscinfo/toCstNpModApplyPage.do?id='+_id+'&_audStsCd='+_audStsCd+'&isModify=1',callback);
		}else if(_cstTypCd == 2){
			Add_navTab('tab_customer_corp_mod'+_id,'法人变更申请','<%=path%>/customer/cstbscinfo/toCstCorpModApplyPage.do?id='+_id+'&_audStsCd='+_audStsCd+'&isModify=1',callback);
		}
	}

	//创建项目
	function createProjectRow(_cstId, _cstNm){
		var callback = function(){
			//alert("callback");
		}
		var fromPrjFlag = false;
		var params = "?cstId="+_cstId+"&fromPrjFlag="+fromPrjFlag+"&cstNm="+_cstNm;
		var timestamp = (new Date()).valueOf();
		Add_navTab('tab_prj_bsc_info_add'+timestamp,'添加项目信息','<%=path%>/project/prjbscinfo/toAddPage.do'+params,callback);
	}

	function checkIsOrNot(){
		$("#winCertTypCd").change(function(event) {
			if($(this).val()==0){
				$("#sNpVerifyID").show();
			}else{
				$("#sNpVerifyID").hide();
			}
		});
		$("#corpForCertTypCd").change(function(event) {
			if($(this).val()==0){
				$("#sCorpVerifyId").show();
			}else{
				$("#sCorpVerifyId").hide();
			}
		});

	}

	//客户类型选择事件
	function winSelectCustomerTypeChangeEvent(){
		$("#win_select_customer_type").change(function(event) {
			var div_customer_type_form = liger.get("div_customer_type_form");
			var typ =$(this).val();
			if (typ == CustomerConstant.CST_TYPE_NP_CD) {
				$("#win_corp_block_id").css('display','none');
				$("#win_np_block_id").css('display','block');

				//取消法人验证
				div_customer_type_form.setFieldValidate("corpCstNm", {
					required: false,
					maxlength:30
				});

				div_customer_type_form.setFieldValidate("corpCertTypCd", {
					required: false,
					select: false
				});

				div_customer_type_form.setFieldValidate("corpForCertTypCd", {
					required: false,
					select: false
				});

				div_customer_type_form.setFieldValidate("corpCertNo", {
					required: false
				});
				div_customer_type_form.setFieldValidate("corpLowerNm", {
					required: false,
					nmcharacter:true,
					maxlength:20
				});
				div_customer_type_form.setFieldValidate("corpLowerCertNo", {
					required: false,
					idcardno: false
				});

				//添加自然人验证
				div_customer_type_form.setFieldValidate("winNpCertNo", {
					required: true
				});

				div_customer_type_form.setFieldValidate("winNpCstNm", {
					required: true,
					nmcharacter:true,
					maxlength:20
				});

				div_customer_type_form.setFieldValidate("winCertTypCd", {
					required: true,
					select: true
				});

			}else if (typ == CustomerConstant.CST_TYPE_CORP_CD) {
				//显示法人, 隐藏自然人
				$("#win_corp_block_id").css('display','block');
				$("#win_np_block_id").css('display','none');

				//取消自然人验证
				div_customer_type_form.setFieldValidate("winNpCstNm", {
					required: false,
					nmcharacter:true,
					maxlength:20
				});

				div_customer_type_form.setFieldValidate("winNpCertNo", {
					required: false
				});

				div_customer_type_form.setFieldValidate("winCertTypCd", {
					required: false,
					select: false
				});

				//新增法人验证

				div_customer_type_form.setFieldValidate("corpCstNm", {
					required: true,
					maxlength:30
				});

				div_customer_type_form.setFieldValidate("corpCertTypCd", {
					required: true,
					select: true
				});
				div_customer_type_form.setFieldValidate("corpForCertTypCd", {
					required: true,
					select: true
				});
				div_customer_type_form.setFieldValidate("corpCertNo", {
					required: true
				});
				div_customer_type_form.setFieldValidate("corpLowerNm", {
					required: true,
					nmcharacter:true,
					maxlength:20
				});
				div_customer_type_form.setFieldValidate("corpLowerCertNo", {
					required: true,
					idcardno: false,
					maxlength:18
				});

			}else{
				$.ligerDialog.SQalert({content: "客户类型无效!", SQ_type: "warning"});
			}
		});
	}

	//身份证第三方验证事件-自然人
	function npVerifyIDEvent(){
		$(".addNpVerifyID").on('click', function(event) {
			//这里要区分当前是选择的自然人还是法人
			var currentType = $("#win_select_customer_type").val();
			if(currentType == CustomerConstant.CST_TYPE_NP_CD){
				if($("#addNpVerifyID").attr("pass") == 'y'){
					return;
				}
			}else if(currentType == CustomerConstant.CST_TYPE_CORP_CD){
				if($("#addCorpVerifyID").attr("pass") == 'y'){
					return;
				}
			}else{
				return;
			}

			//上面是一个完成验证,如果完成了就停止,下面继续
			var _this = this;
			var wait_dialog = UIUtils.alertWaiting(LogUtils.LOG_CMM_DATA_LOADING);
			var data = ligerPersonForm.getData();
			var cstNm;//客户名称
			var certNo;//证件号码
			var validNmTip;
			var validNoTip;
			if(currentType == CustomerConstant.CST_TYPE_NP_CD){
				if($("#addNpVerifyID").attr("pass") == 'y'){
					return;
				}
				cstNm = data.winNpCstNm;//客户名称
				certNo = data.winNpCertNo;//身份证号码
				validNmTip = LogUtils.LOG_CUST_NAME_NOT_EMPTY;
				validNoTip = LogUtils.LOG_CUST_ID_CARD_NOT_EMPTY;

			}else if(currentType == CustomerConstant.CST_TYPE_CORP_CD){
				if($("#addCorpVerifyID").attr("pass") == 'y'){
					return;
				}
				cstNm = data.corpLowerNm;//法定代表人名称
				certNo = data.corpLowerCertNo;//法定代表人身份证号码
				validNmTip = LogUtils.LOG_CUST_CORP_NAME_NOT_EMPTY;
				validNoTip = LogUtils.LOG_CUST_CORP_ID_CARD_VALID_NO_PASS;
			}

			if(!cstNm){
				wait_dialog.close();
				UIUtils.alertWarning(validNmTip);
				return; //验证不通过，不执行以下代码
			}
			if(!certNo){
				wait_dialog.close();
				UIUtils.alertWarning(validNmTip);
				return; //验证不通过，不执行以下代码
			}

			_mySelfIDImgUrl = "";//每次验证都要赋空值在赋新值

			$.ajax({
				type: 'post',
				dataType:'json',
				data:{cstNm:cstNm,certNo:certNo},
				url: '<%=path%>/customer/cstbscinfo/validateIdCard.do',
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						if(msg.data){
							if(msg.data.absolutePath){
								//把这个地址记录上,后面要随保存数据一起存储
								_mySelfIDImgUrl = msg.data.absolutePath;
							}
						}
						//说明已经三方验证通过
						UIUtils.alertSuccess(msg.info);
						//验证通过后直接禁用输入框
						if(currentType == CustomerConstant.CST_TYPE_NP_CD){
							liger.get("winNpCstNm").setDisabled(true);
							liger.get("winNpCertNo").setDisabled(true);
							liger.get("winCertTypCd").setDisabled(true);
							$(_this).closest(".addNpVerifyID").html(getVerfiedIDHtmlPass());
						}else if(currentType == CustomerConstant.CST_TYPE_CORP_CD){
							liger.get("corpLowerNm").setDisabled(true);
							liger.get("corpLowerCertNo").setDisabled(true);
							liger.get("corpForCertTypCd").setDisabled(true);
							$(_this).closest(".addNpVerifyID").html(getCorpVerfiedIDHtmlPass());
						}
						$(".liger_tip").ligerTip(); // HTML元素更新后，重新ligerTip实例化
					}else{//验证未通过
						UIUtils.alertWarning(msg.info);
					}
				}
			});

		});
	};

	//验证身份证未通过
	function getVerfiedIDHtmlNopass(){
		var html="<a href='javascript:;' id='addNpVerifyID' pass='n' class='liger_tip' title='"+LogUtils.LOG_CMM_VALID_FAIL+"'><i class='sqIco sqIco_2'></i></a>";
		return html;
	}

	//验证身份通过
	function getVerfiedIDHtmlPass(){
		var html="<span class='liger_tip' id='addNpVerifyID' pass='y' title='"+LogUtils.LOG_CMM_VALID_PASS+"'><i class='sqIco sqIco_1'></i></span>";
		return html;
	}

	//身份未验证标记
	function getVerfiedIDHtmlDefault(){
		var html = "<a href=\"javascript:;\" id=\"addNpVerifyID\" pass='n' class=\"liger_tip\" title=\"未验证\"><i class=\"sqIco sqIco_8\"></i></a>";
		return html;
	}


	//验证身份证未通过-法人
	function getCorpVerfiedIDHtmlNopass(){
		var html="<a href='javascript:;' id='addCorpVerifyID' pass='n' class='liger_tip' title='"+LogUtils.LOG_CMM_VALID_FAIL+"'><i class='sqIco sqIco_2'></i></a>";
		return html;
	}

	//验证身份通过-法人
	function getCorpVerfiedIDHtmlPass(){
		var html="<span class='liger_tip' id='addCorpVerifyID' pass='y' title='"+LogUtils.LOG_CMM_VALID_PASS+"'><i class='sqIco sqIco_1'></i></span>";
		return html;
	}

	//身份未验证标记-法人
	function getCorpVerfiedIDHtmlDefault(){
		var html = "<a href=\"javascript:;\" id=\"addCorpVerifyID\" pass='n' class=\"liger_tip\" title=\"未验证\"><i class=\"sqIco sqIco_8\"></i></a>";
		return html;
	}

	function clearBtn(){
		var form = new liger.get("searchBar");
		form.clear();
	}

	function iframeResize () {
		if (parent.mainApp) {
			parent.mainApp.parentTab.onResize();
		};
	}

	//显示流程：流程实例ID,状态,业务主键(拖车主表ID)
	function commShowFlow(_pInstId, _audStsCd, _businessKey){
		if(StringUtils.isEmpty(_pInstId)){
			UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
			return;
		}
		var _formUrl = "/customer/cstbscinfo/toCstModDetailPage.do?isFlow=1@@isModify=0@@modId=";
		var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
		Add_navTab('tab_cust_mod_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
	}

	//初始化Tab页签
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onAfterSelectTabItem: function(tabid) {
				//获取当前选中的客户ID供其它页面使用
				var sCstId = $("#sCstId").val();
				if(tabid!="tabA"){
					if(!sCstId){
						$.ligerDialog.SQalert({content: "请选择一条信息！", SQ_type: "warning"});
						return false; //验证不通过，不执行以下代码
					}
				}
				switch (tabid){
					case "tabB":
						pageInTab.setTabItemSrc(tabid, "<%=path%>/customer/cstbscinfo/toFlowPage.do?sCstId="+sCstId);
						break;
				}
				SetIframe_height();
			}
		});
		//设置页签
		$.extend(true, pageInApp, {
			pageInTab: pageInTab
		});
	};
</script>

</body>
</html>